#include<iostream>
#include<string.h>
using namespace std;
void Print(int a[], int n)
{
	int i = 0;
	for (i; i < n; i++)
	{
		cout << a[i] << ' ';
	}
	cout << endl;
}
void BubbleSort(int a[], int n)
{
	int i = 0;
	for (i; i < n-1; i++)
	{
		int j = 0;
		for (j; j < n - i - 1; j++)
		{
			if (a[j + 1] < a[j])
			{
				std::swap(a[j], a[j + 1]);
			}
		}
	}
}
void SelectSort(int a[], int n)
{
	int begin = 0;
	int end = n - 1;
	while (begin < end)
	{
		int maxi = end;
		int mini = begin;
		int i = begin ;
		for (i; i <= end; i++)
		{
			if (a[maxi] < a[i])
				maxi = i;
			if (a[mini] > a[i])
				mini = i;
		}
		std::swap(a[maxi], a[end]);
		if (mini == end)
			mini = maxi;
		std::swap(a[mini], a[begin]);
		begin++;
		end--;
	}
}
void QuickSort(int a[], int begin,int end)
{
	if (begin >= end)
		return;
	int left = begin;
	int right = end;
	while (left < right)
	{
		while (a[right] > a[begin] && right > left)
			right--;
		while (a[left] < a[begin] && left < right)
			left++;
		swap(a[left], a[right]);
	}
	swap(a[begin], a[left]);
	QuickSort(a, begin, left);
	QuickSort(a, left+1, end);
}

int main()
{
	int a[200] = { 0 };
	int n = 0;
	while (1)
	{
		int x;
		cin >> x;
		if (x == 0)
			break;
		a[n++] = x;
	}
	int b[200] = { 0 };
	memcpy(b, a, sizeof(int) * n);
	int c[200] = { 0 };
	memcpy(c, a, sizeof(int) * n);
	BubbleSort(a, n);
	Print(a,n);
	SelectSort(b, n);
	Print(b, n);
	QuickSort(c,0,n-1);
	Print(c, n);
}